package com.ihr360.payroll.controller.payrollconfig;

import com.google.common.collect.Maps;
import com.ihr360.commons.model.meta.table.DynamicCell;
import com.ihr360.maven.plugin.ModuleCodeStore;
import com.ihr360.maven.plugin.annotation.FunctionDefinition;
import com.ihr360.maven.plugin.annotation.ModuleDefinition;
import com.ihr360.payroll.model.dto.salary.meta.SalaryField;
import com.ihr360.payroll.service.payroll.PayrollConfigDemoService;
import io.swagger.annotations.Api;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@Api(value = "薪资示例数据")
@RestController
@RequestMapping("/PayrollConfigDemoes")
@ModuleDefinition(mainModuleCode = ModuleCodeStore.Module.SALARY_CODE,
        mainModuleName = ModuleCodeStore.Module.SALARY_NAME,
        subModuleCode = ModuleCodeStore.Module.Salary.SALARY_SETTING_CODE,
        subModuleName = ModuleCodeStore.Module.Salary.SALARY_SETTING_NAME,
        hasExtendsAbstractRestController = true)

public class PayrollConfigDemoController {

    Logger logger = LoggerFactory.getLogger(getClass());

    @Autowired
    private PayrollConfigDemoService payrollConfigDemoService;

    @FunctionDefinition(functionName = "薪资表Demo数据计算展示", functionCode = ModuleCodeStore.Function.PAYROLL_CONFIG)
    @PostMapping(value = "/demoCalc", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public Map<String, DynamicCell> demoSalaryCalc(@RequestBody List<SalaryField> salaryFields) {
        //demo数据计算，出错不影响主流程
        try {
            return payrollConfigDemoService.demoSalaryCalc(salaryFields);
        } catch (Exception e) {
            logger.error(e.toString());
        }
        return Maps.newHashMap();
    }
}
